using System;
using System.Diagnostics;

using Impact.Infrastructure.Logging;

using StructureMap;

namespace Impact.Infrastructure.Exceptions
{
    /// <summary>
    /// class responsible for managing exceptions that are thrown
    /// </summary>
    public static class ExceptionManager
    {

        /// <summary>
        /// default handling procedure for a single message
        /// </summary>
        public static void Handle( string message )
        {
            ILogger logger = ObjectFactory.GetInstance<ILogger>();
            logger.Write( message, TraceEventType.Warning );
        }

        /// <summary>
        /// default handling procedure for a single message
        /// </summary>
        public static void Handle( string message, TraceEventType severity )
        {
            ILogger logger = ObjectFactory.GetInstance<ILogger>();
            logger.Write( message, severity );
        }


        /// <summary>
        /// default handling procedure for a single exception
        /// </summary>
        public static void Handle(Exception ex)
        {
            ILogger logger = ObjectFactory.GetInstance<ILogger>();
            logger.Write(ex);
            throw ex;
        }

        /// <summary>
        /// default handling procedure for an exception and a message
        /// </summary>
        public static void Handle(string message, Exception ex)
        {
            Exception handledEx = new ApplicationException(message, ex);
            ILogger logger = ObjectFactory.GetInstance<ILogger>();
            logger.Write(handledEx);
            throw handledEx;
        }



    }


}
